﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.BLL.Cached;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Model.CommonObject;

namespace ZBJF.Warranty.WeiXinPayAPI
{
    public class WxPayConfig
    {
        static AppConfigEntity entity = new AppConfigEntity();
        static WxPayConfig() {
            entity = AppConfigCached.GetAppConfig();
        }
        //=======【基本信息设置】==============================================================================
        /// <summary>
        /// 绑定支付的APPID（必须配置）
        /// </summary>
        internal static string APPID {
            get {
                string appId= entity.WeiXin_AppId;
                if (string.IsNullOrEmpty(appId)) {
                    LogHelper.WriteLog("微信公众号绑定支付的appId未配置", LogType.tag);
                }
                return appId;
            }
        }

        /// <summary>
        /// 商户号（必须配置）
        /// </summary>
        internal static string MCHID
        {
            get
            {
                string mch_id = entity.WeiXin_MchId;
                if (string.IsNullOrEmpty(mch_id))
                {
                    LogHelper.WriteLog("商户号mch_id未配置", LogType.tag);
                }
                return mch_id;
            }
        }

        /// <summary>
        /// 商户支付密钥，参考开户邮件设置（必须配置）
        /// </summary>
        internal static string KEY
        {
            get
            {
                string key = entity.WeiXin_Key;
                if (string.IsNullOrEmpty(key))
                {
                    LogHelper.WriteLog("商户支付密钥key未配置", LogType.tag);
                }
                return key;
            }
        }

        /// <summary>
        /// 公众帐号secert（仅JSAPI支付的时候需要配置）
        /// </summary>
        internal static string APPSECRET
        {
            get
            {
                string appSecret = entity.WeiXin_AppSecret;
                if (string.IsNullOrEmpty(appSecret))
                {
                    LogHelper.WriteLog("公众帐号appSecret未配置(仅JSAPI支付的时候需要配置）", LogType.tag);
                }
                return appSecret;
            }
        }


        //=======【证书路径设置】================================================================================
        /// <summary>
        /// 证书路径,注意应该填写绝对路径（仅退款、撤销订单时需要）
        /// </summary>
        internal static string SSLCERT_PATH
        {
            get
            {
                string sslCert_path = entity.WeiXin_SSLCertPath;
                if (string.IsNullOrEmpty(sslCert_path))
                {
                    LogHelper.WriteLog("证书路径,注意应该填写绝对路径（仅退款、撤销订单时需要）未配置", LogType.tag);
                }
                return sslCert_path;
            }
        }

        /// <summary>
        /// 证书密钥（仅退款、撤销订单时需要）
        /// </summary>
        internal static string SSLCERT_PASSWORD
        {
            get
            {
                string sslCert_password = entity.WeiXin_SSLCertPassword;
                if (string.IsNullOrEmpty(sslCert_password))
                {
                    LogHelper.WriteLog("证书密钥（仅退款、撤销订单时需要）未配置", LogType.tag);
                }
                return sslCert_password;
            }
        }


        //=======【支付结果通知url】============================================================================
        /// <summary>
        /// 支付结果通知回调url，用于商户接收支付结果
        /// </summary>
        internal static  string NOTIFY_URL
        {
            get
            {
                string tenPayV3Notify = entity.WeiXin_NotifyUrl;
                if (string.IsNullOrEmpty(tenPayV3Notify))
                {
                    LogHelper.WriteLog("支付结果通知回调url未配置，用于商户接收支付结果", LogType.tag);
                }
                return tenPayV3Notify;
            }
        }

    }
}
